/***************************************************************************
 *   Copyright (C) 2008 by Tomasz Dubik                                    *
 *   tdubik@gmail.com                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QDebug>
#include <QUrl>

#include "settings.h"
#include "configdlg.h"

ConfigDlgImpl::ConfigDlgImpl(QWidget* parent):QDialog(parent)
{

	setupUi(this);
    setConnections();
    setData();
}

void ConfigDlgImpl::setConnections()
{
    connect(m_pSyncEnabled, SIGNAL( stateChanged(int)), this, SLOT( syncStateChanged(int)));
    connect(m_rememberPass, SIGNAL( stateChanged(int)), this, SLOT( passStateChanged(int)));
    connect(m_passiveFtp, SIGNAL( stateChanged(int)), this, SLOT( passiveStateChanged(int)));
    connect(m_host, SIGNAL ( editingFinished()), this, SLOT(hostEditingFinished()));
    connect(m_username, SIGNAL ( editingFinished()), this, SLOT(loginEditingFinished()));
    connect(m_password, SIGNAL ( editingFinished()), this, SLOT(passEditingFinished()));
}

void ConfigDlgImpl::setData()
{
    m_pSyncEnabled->setChecked(Settings::value(SettingsKeys::AppSettings_GenEnableSync).toBool());
    m_rememberPass->setChecked(Settings::value(SettingsKeys::AppSettings_FtpSavePassword).toBool());
    m_passiveFtp->setChecked(Settings::value(SettingsKeys::AppSettings_FtpPassive).toBool());
    m_host->setText(Settings::value(SettingsKeys::AppSettings_FtpHost).toString());
    m_password->setText(Settings::value(SettingsKeys::AppSettings_FtpPassword).toString());
    m_username->setText(Settings::value(SettingsKeys::AppSettings_FtpUsername).toString());
}

void ConfigDlgImpl::syncStateChanged ( int state )
{
    Settings::setValue(SettingsKeys::AppSettings_GenEnableSync, state);
}

void ConfigDlgImpl::passStateChanged( int state )
{
    Settings::setValue(SettingsKeys::AppSettings_FtpSavePassword, state);
}

void ConfigDlgImpl::passiveStateChanged(int state)
{
    Settings::setValue(SettingsKeys::AppSettings_FtpPassive, state);
}
void ConfigDlgImpl::loginEditingFinished()
{
    Settings::setValue(SettingsKeys::AppSettings_FtpUsername, m_username->text());
}

void ConfigDlgImpl::passEditingFinished()
{
    Settings::setValue(SettingsKeys::AppSettings_FtpPassword, m_password->text());
}

void ConfigDlgImpl::hostEditingFinished()
{
    Settings::setValue(SettingsKeys::AppSettings_FtpHost, m_host->text());
}

//eof
